<!DOCTYPE html>
<html>
<head>
	<title>数组的扩展</title>
</head>
<body>
<script type="text/javascript">
	
let arrayLike = {
    '0': 'a',
    '1': 'b',
    '2': 'c',
    length: 3
};
// 1. Array.form                            转换伪数组
// ES5的写法
var arr1 = [].slice.call(arrayLike); 
console.log(arr1);
// ES6的写法
let arr2 = Array.from(arrayLike); 
console.log(arr2);



// 2. Array.of 						                   将一组值转换为数组
console.log(Array.of(1, 2, 3));



// 3. find和findIndex 				               返回第一个返回值为true的成员
let res = [1, 5, 10, 15].find(function(value, index, arr) {
  return value > 9;
})
console.log(res);
res = [1, 5, 10, 15].findIndex(function(value, index, arr) {
  return value > 9;
})
console.log(res);



// 3. fill() 						                     填充数组
console.log(['a', 'b', 'c'].fill(7, 1, 3));



// 4. entries()，keys()和values()            数组的遍历
for (let index of ['a', 'b'].keys()) {
  console.log(index);
}
for (let val of ['a', 'b'].values()) {
  console.log(val);
}

for (let [index, val] of ['a', 'b'].entries()) {
  console.log(index, val);
}


</script>
</body>
</html>